package com.gy.hadoop.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URI;

/**
 * 上传文件到hdfs
 */
public class FileCopyFromLocal {

    public static void main(String[] args) {
        String source = "/Users/mac/Downloads/workspace/kkb-bigdata/src/main/resources/test.txt";
        String destination = "hdfs://gyClusterHa/data/file1";

        try {
            InputStream in = new BufferedInputStream(new FileInputStream(source));
            Configuration conf = new Configuration();
            FileSystem fs = FileSystem.get(URI.create(destination), conf, "spadger");
            FSDataOutputStream out = fs.create(new Path(destination));
            IOUtils.copyBytes(in, out, 1024, true);
        } catch (Exception e) {

        }
    }
}
